<?
//传递产品的id，然后根据产品id，查出其所属分类的名字。
//为了输出格式的灵活，所以第二个参数$termnumber用来判断返回term0~term5

//传递产品的id，查出term0至term5个个分类的名字和id
function gettermdate($dataid, $termnumber)
{

    global $table_Prefix;
    global $sys_list_table;
    global $sys_term_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = 'relation';//$sys_list_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
    $sort_by = "nid";
    $sort_order = "desc";
//设置需要搜索的表格的排序项和升降项


    $result = mysql_query("SELECT * FROM $table where detail_nid = '$dataid' and belong is NULL " ); //	查出这个id的产品的各个termid
	
	
	$cat_list = array();

    while ($row = mysql_fetch_assoc($result)) {

		
        $cat_list[] = $row;
     	
    }
	
	$return_cat_list = array();
	
	if($cat_list){
		
	
		foreach($cat_list as $val){
			
			$cat_name_list = array();
			
			$cat_name_arr = get_cat_all_name($val['term_nid'],$cat_name_list);
			
			if($cat_name_arr){
				rsort($cat_name_arr);
				
				$return_cat_list[] = $cat_name_arr;
			}
			
		}
	}
	
	return $return_cat_list;
}

function gettermdate_brand($dataid, $termnumber)
{

    global $table_Prefix;
    global $sys_list_table;
    global $sys_term_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = 'relation';//$sys_list_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
    $sort_by = "nid";
    $sort_order = "desc";
//设置需要搜索的表格的排序项和升降项


    $result = mysql_query("SELECT * FROM $table where detail_nid = '$dataid' and belong = 'brand' " ); //	查出这个id的产品的各个termid
	
	
	$cat_list = array();

    while ($row = mysql_fetch_assoc($result)) {

		
        $cat_list[] = $row;
     	
    }
	
	$return_cat_list = array();
	
	if($cat_list){
		
	
		foreach($cat_list as $val){
			
			$cat_name_list = array();
			
			$cat_name_arr = get_cat_all_name($val['term_nid'],$cat_name_list);
			
			if($cat_name_arr){
				rsort($cat_name_arr);
				
				$return_cat_list[] = $cat_name_arr;
			}
			
		}
	}
	
	return $return_cat_list;
}


function get_cat_all_name($cat_id,$cat_name_list){
	
	 global $table_Prefix;
	 
	$result = mysql_query("SELECT * FROM ".$table_Prefix."term where nid = '".$cat_id."'"); //	查出这个id的产品的各个termid
			
	$row1 = mysql_fetch_assoc($result);
			
	
	if($row1['interm'] != 'root' && $row1['interm'] != '' && $row1[$row1['interm']] > 0){
			
		$cat_name_list[count($cat_name_list)] = $row1['name'] ;
			
		return get_cat_all_name($row1[$row1['interm']],$cat_name_list);
	}
	else{
		$cat_name_list[count($cat_name_list)] = $row1['name'] ;
		
		return $cat_name_list;	
	}
	
	
}


?>



<?
//后台用检查账号等级。
function check_admin_type()
{


//根据传过来的session账户名，确定账户的类型，从而判断权限

    global $table_Prefix;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = "login_admin";
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
    $sort_by = "nid";
    $sort_order = "desc";
//设置需要搜索的表格的排序项


    $check_name = $_SESSION['username'];

    $result = mysql_query("select * from $table where name = '$check_name' ");

    while ($row = mysql_fetch_array($result)) {
        $admin_nid = $row['nid'];
        $admin_type_now=$row['admin_term'];
        $admin_password = $row['admin_password'];
    }


    if ($admin_type_now == 1) {
        return "admins";
    } elseif ($admin_type_now == 2) {
        return "editor";
    }

}


?>







<?php
//截取utf8字符串
function utf8Substr($str, $from, $len)
{
    return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $from . '}' .
        '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $len . '}).*#s',
        '$1', $str);
}

?>



<?
//获取数据库中id最大值

function get_max_nid($term_or_detail)
{
    global $table_Prefix;
    global $sys_term_table; //板块的分类表格名
    global $sys_list_table; //板块的详细表格
//设置需要搜索的表格的前缀后缀


    $table_Suffix = "detail";
    if ($term_or_detail == "term") {
        $table_Suffix = "term";
    }

    $table = $table_Prefix . $table_Suffix;

    $result = mysql_query("select * from $table where nid=(select max(nid) from $table) ");

    while ($row = mysql_fetch_array($result)) {
        $max_nid = $row['nid'];
    }

    return $max_nid + 1;
}

?>


<?

//传递单个需要对比的变量和变量数组，
//检测单个变量是否存在于变量数组中。

function compare_term($target, $target_list)
{
    $term_exist = false;

    for ($i = 0; $i < count($target_list); $i++) {
        if ($target == $target_list[$i]) {
            $term_exist = true;
        }
    }

    return $term_exist;
}

?>


<?php
//获取分类id，然后给对用id的数据，clickrate加1
function term_clickrate($trans_nid, $term_detail_clickrate)
{

    $term_detail_clickrate = $term_detail_clickrate + 1;


    global $table_Prefix;
    global $sys_list_table;
    global $sys_term_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_term_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//开始把点击率插入数据库
    $clickrate_increase = "update $table SET
	clickrate          =    '$term_detail_clickrate'
	where nid='$trans_nid'";

    $query = mysql_query($clickrate_increase) or die ('更新点击率失败');


}

?>







<?php
//获取分类id，然后给对用id的数据，clickrate加1
function detail_clickrate($trans_nid, $detail_clickrate)
{

    $detail_clickrate = $detail_clickrate + 1;


    global $table_Prefix;
    global $sys_list_table;
    global $sys_term_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_list_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//开始把点击率插入数据库
    $clickrate_increase = "update $table SET
	clickrate          =    '$detail_clickrate'
	where nid='$trans_nid'";

    $query = mysql_query($clickrate_increase) or die ('更新点击率失败');


}

?>





<?
//传递分类的id，然后根据分类id，查出其上级分类的名字。
//为了输出格式的灵活，所以第二个参数$termnumber用来判断返回term0~term5

//传递产品的id，查出term0至term5个个分类的名字和id
function getallterm($targetid, $getdata)
{

    global $table_Prefix;
    global $sys_list_table;
    global $sys_term_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_term_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀


    $result = mysql_query("SELECT * FROM $table where nid = '$targetid'"); //查出这个id的产品的各个termid

    while ($row = mysql_fetch_array($result)) {

        $target_interm = $row['interm'];
        $target_term1 = $row['term1'];
    }


    if ($target_interm != 'root') {

//	根据这些term的id查出各自的名字

        $result2 = mysql_query("SELECT * FROM $table where nid = '$target_term1'");

        while ($row = mysql_fetch_array($result2)) {
            $term0_name = $row['name'];
            $term0_nid = $row['nid'];
            $term0_url = $row['url'];
        }


    }

    mysql_close($con);


    if ($getdata == 'id') {
        return $target_term1;
    } else if ($getdata == 'url') {
        return $term0_url;
    } else {
        return $term0_name;
    }


}


?>






<?
function id_get_term($targetid, $target_date)
{
    global $table_Prefix;
    global $sys_list_table;
    global $sys_term_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_term_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


    $result = mysql_query("SELECT * FROM $table where nid = '$targetid'"); //查出这个id的产品

    while ($row = mysql_fetch_array($result)) {
        $target_nid = $row['nid'];
        $target_name = $row['name'];
        $target_url = $row['url'];
    }


    if ($target_date == "url") {
        $return_date = $target_url;
    } else {
        $return_date = $target_name;
    }

    return $return_date;


}


?>







<?
//获取单挑数据是否有外链处理
//直接通过判断storage是否为空，来输入网址前缀

function link_prefix($site_domain, $storage)
{

    if ($storage) {
        $link_prefix = $storage;
    } else {
        $link_prefix = $site_domain;
    }

    return $link_prefix;


}

?>





<?php
// 分析返回用户操作系统名称//
function getSystem()
{
    $sys = $_SERVER['HTTP_USER_AGENT'];
    if (stripos($sys, "NT 6.1")) {
        return true;
    } else if (stripos($sys, "NT 6.2")) {
        return true;
    } else if (stripos($sys, "NT 6.0")) {
        return true;
    } else if (stripos($sys, "NT 5.1")) {
        return true;
    } else if (stripos($sys, "NT 5.2")) {
        return true;
    } else if (stripos($sys, "NT 5")) {
        return true;
    } else if (stripos($sys, "NT 4.9")) {
        return true;
    } else if (stripos($sys, "NT 4")) {
        return true;
    } else if (stripos($sys, "98")) {
        return true;
    } else if (stripos($sys, "95")) {
        return true;
    } else {
        return false;
    }
}

/* 上面是判断操作系统的，并返回值，如果是电脑操作系统返回TRUE*/


?>




<?
//判断字符长度大于设定值，则阶段并加省略号
//中文字3字节，英文数字1字节
function cutstr($text, $long)
{
    if (utf8_strlen($text) > $long) {
        $function_result = utf8Substr($text, 0, $long) . "...";
    } else {
        $function_result = $text;
    }

    return $function_result;
}

?>








<?
function utf8_strlen($str)
{
    $count = 0;
    for ($i = 0; $i < strlen($str); $i++) {
        $value = ord($str[$i]);
        if ($value > 127) {
            $count++;
            if ($value >= 192 && $value <= 223) $i++;
            elseif ($value >= 224 && $value <= 239) $i = $i + 2;
            elseif ($value >= 240 && $value <= 247) $i = $i + 3;
            else die('Not a UTF-8 compatible string');
        }
        $count++;
    }
    return $count / 2;
}

?>




<?
//获取指定板块的伪静态url================

function menu_url($str)
{
    global $table_Prefix;
    global $sys_list_table;
    global $sys_term_table;
    global $sys_plate_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_plate_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

    $result = mysql_query("SELECT * FROM $table where mid = '$str' ");

    while ($row = mysql_fetch_array($result)) {
        $url = $row['url'];
    }

    return $url;

}

//获取指定板块的名称
function menu_name($str)
{
    global $table_Prefix;
    global $sys_plate_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_plate_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

    $result = mysql_query("SELECT * FROM $table where mid = '$str' ");

    while ($row = mysql_fetch_array($result)) {
        $name = $row['name'];
    }

    return $name;

}

//获取指定板块的名称
function menu_title($str)
{
    global $table_Prefix;
    global $sys_plate_table;
    $table_Suffix = $sys_plate_table;
    $table = $table_Prefix . $table_Suffix;

    $result = mysql_query("SELECT * FROM $table where mid = '$str' ");

    while ($row = mysql_fetch_array($result)) {
        $title = $row['title'];
    }

    return $title;

}


//获取指定板块的名称
function menu_term($str)
{
    global $table_Prefix;
    global $sys_plate_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_plate_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

    $result = mysql_query("SELECT * FROM $table where mid = '$str' ");

    while ($row = mysql_fetch_array($result)) {
        $term = $row['term'];
    }

    return $term;

}


//获取指定板块的名称
function menu_page_list($str)
{
    global $table_Prefix;
    global $sys_plate_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_plate_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

    $result = mysql_query("SELECT * FROM $table where mid = '$str' ");

    while ($row = mysql_fetch_array($result)) {
        $page_list = $row['page_list_num'];
    }

    return $page_list;

}


//获取指定板块的名称
function menu_term_publish($str)
{
    global $table_Prefix;
    global $sys_plate_table;
//设置需要搜索的表格的前缀后缀
    $table_Suffix = $sys_plate_table;
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

    $result = mysql_query("SELECT * FROM $table where mid = '$str' ");

    while ($row = mysql_fetch_array($result)) {
        $term_publish = $row['term_public'];
    }

    return $term_publish;

}











//过滤特殊字符
 function ReplaceSpecialChar($C_char){//过滤特殊字符
     $C_char = HTMLSpecialChars($C_char); //将特殊字元转成 HTML 格式
     $C_char = str_replace(",", "，", $C_char); //替换英文逗号,
     $C_char = str_replace("<", "&lt", $C_char); //替换英文小破折号<
     $C_char = str_replace(">", "&gt", $C_char);//替换英文小破折号>
     $C_char = str_replace("'", "''", $C_char);//替换英文单引号 '
     $C_char = str_replace("{", "《", $C_char);//替换英文大括号{
     $C_char = str_replace("}", "》", $C_char);//替换英文大括号}
     $C_char = str_replace("(", "（", $C_char);//替换英文小括号(
     $C_char = str_replace("）", "）", $C_char);//替换英文小括号）

     htmlentities($C_char, ENT_QUOTES);//替换英文双引号 "

 return $C_char;
 }




?>